package com.yy.QSManage.common;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    @ApiModelProperty("状态码")
    private Integer code; //编码
    @ApiModelProperty("请求数据")
    private T data; //数据
    @ApiModelProperty("错误信息")
    private String msg = "success"; //错误信息
    //    private Map map = new HashMap(); //动态数据
//    private Map<String,Object> map = new HashMap<>(); //动态数据

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.code = 200;
        result.data = null;
        return result;
    }

    /**
     * 成功
     * @param object
     * @return
     * @param <T>
     */
    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<>();
        result.code = 200;
        result.data = object;
        return result;
    }

    //失败信息
    public static <T> Result<T> error() {
        Result<T> result = new Result<>();
        result.code = 0;
        result.msg = "接口异常！";
        return result;
    }

    //失败信息
    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.code = 0;
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> error(String msg, Integer code) {
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        return result;
    }
    //添加动态数据
//    public Result<T> add(String key, Object value) {
//        this.map.put(key, value);
//        return this;
//    }
}
